<template>
  <div class="forum-list-wrap">
    <div class="banner">
      <el-carousel height="5.5rem">
        <el-carousel-item v-for="(item, index) in bannerList" :key="index">
          <div class="banner-img" @click="clickBannerFun(item)">
            <img :src="item.image" alt="" />
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>

    <!-- 新增tab切换 -->

    <div class="type">
      <div
        class="type-item"
        :class="{ 'type-item-active': layoutType == 'grid' }"
        @click="layoutType = 'grid'"
      >
        <i class="el-icon-menu"></i>
      </div>
      <div
        class="type-item"
        :class="{ 'type-item-active': layoutType == 'list' }"
        @click="layoutType = 'list'"
      >
        <i class="el-icon-s-unfold"></i>
      </div>
    </div>

    <div class="list">
      <template v-if="layoutType == 'list'">
        <StudyItem v-for="(item, index) in list" :item="item" :key="index"></StudyItem>
      </template>
      <div class="data" v-else>
        <div class="data-item" v-for="(item, index) in list" :key="index">
          <StudyItem2 :item="item"></StudyItem2>
        </div>
      </div>
    </div>

    <div class="pagination">
      <el-pagination background layout="prev, pager, next" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import StudyItem from "./pageComponents/study-item.vue";
import StudyItem2 from "./pageComponents/study-item2.vue";
import { getBanner } from "@/api/common";
import { getCompilations } from "@/api/study";
export default {
  components: {
    StudyItem,
    StudyItem2,
  },
  data() {
    return {
      bannerList: [],
      layoutType: "list", // list grid
      list: [],
      total: 0,
      params: {
        page: 1,
        limit: 10,
      },
    };
  },
  mounted() {
    this.getListFun();
    this.getBannerFun();
  },
  methods: {
    getBannerFun() {
      getBanner({
        position: 7,
      }).then((res) => {
        this.bannerList = res.data;
      });
    },
    clickBannerFun(item) {
      if (item.url) {
        window.location.href = item.url;
      }
    },
    selectTabFun(item, index) {
      this.tabCurrent = index;
    },
    getListFun() {
      getCompilations(this.params).then((res) => {
        if (res.code == 200) {
          this.list = res.data.list;
          this.total = res.data.count;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.forum-list-wrap {
  .banner {
    width: 100%;
    height: 5.5rem;
    .banner-img {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }

  .type {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-top: 0.375rem;
    .type-item {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 0.5rem;
      height: 0.5rem;
      background: #eef6fe;
      border-radius: 0.1rem;
      font-size: 0.3125rem;
      color: #4f546b;
      cursor: pointer;
      margin-left: 0.2rem;
    }
    .type-item-active {
      background: #4f8af8;
      color: #fff;
    }
  }

  .list {
    padding-top: 0.5rem;
  }
  .data {
    display: flex;
    flex-wrap: wrap;
    .data-item {
      width: 4.1875rem;
      margin-right: 0.25rem;
      margin-bottom: 0.375rem;
      &:nth-child(4n) {
        margin-right: 0;
      }
    }
  }
  .pagination {
    display: flex;
    justify-content: center;
    padding: 0.375rem 0 1rem;
  }
}

// 新增 tab 筛选样式

.m-cagegory {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 1rem;
  background: rgba(79, 138, 248, 0.1);
  margin-top: 0.4rem;
  box-sizing: border-box;
  padding: 0 0.5rem 0 0;
  .push {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 0.5rem;
    background: #4f8af8;
    border-radius: 0.1rem;
    font-size: 0.2rem;
    color: #fff;
    cursor: pointer;
    user-select: none;
  }
  .m-tab {
    display: flex;
    width: 15rem;
    height: 100%;
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scroll-duration: 1s;
    &::before {
      content: "";
      display: block;
      width: 0.125rem;
      height: 100%;
    }
    &::-webkit-scrollbar {
      height: 0;
      border-radius: 0.025rem;
      background: rgba(0, 0, 0, 0.1);
    }
    &::-webkit-scrollbar-thumb {
      background: #4f8af8;
    }
    .m-tab-item {
      display: flex;
      align-items: center;
      padding: 0 0.375rem;
      font-size: 0.3rem;
      color: #333;
      flex-shrink: 0;
      height: 100%;
      cursor: pointer;
      user-select: none;
    }
    .m-tab-item--active {
      font-weight: 800;
    }
  }
}

// 新增 tab 筛选样式
</style>
